package com.qidian.by.search.controller;

import com.qidian.by.search.dto.SearchItem;
import com.qidian.by.search.service.SearchItemService;
import com.qidian.by.util.pojo.EsResult;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: CoolPro
 * @Description:
 * @Time: 2024-05-15 19:43
 **/
@RestController
public class ESSearchController {
    @Resource
    SearchItemService searchItemService;

    @PostMapping("/insert")
    public EsResult insert(@RequestBody String data) {
        SearchItem item = EsResult.json2object(data, SearchItem.class);
        return EsResult.isSuccess(searchItemService.saveSearchItem(item));
    }

    @GetMapping("/query")
    public EsResult query(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "10") int limit, String kw) {
        return searchItemService.query(page, limit, kw);
    }
}
